﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.DialogUI {
    import Events.*;
    import flash.utils.*;
    import Classes.*;
    import Display.*;

    public class MysteryCrateDialog extends GenericDialog {

        private var m_dialogView:MysteryCrateDialogView;
        private var m_itemNameToPlace:String = "";
        private var m_winnigItem:Item;

        public function MysteryCrateDialog(_arg1:String, _arg2:String="", _arg3:int=0, _arg4:Function=null, _arg5:String="", _arg6:String="", _arg7:Boolean=true, _arg8:int=0, _arg9:String="", _arg10:Function=null, _arg11:String="", _arg12:Boolean=true){
            super(_arg1, _arg2, _arg3, this.onPlaceNowClose, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10, _arg11);
            addEventListener(MarketEvent.MARKET_BUY, UI.onMarketClick, false, 0, true);
        }
        public function get itemNameToPlace():String{
            return (this.m_itemNameToPlace);
        }
        override protected function createDialogView(_arg1:Dictionary):GenericDialogView{
            this.m_dialogView = new MysteryCrateDialogView(_arg1, m_message, m_dialogTitle, m_type, m_callback, m_icon, m_iconPos, "", null, m_customOk);
            return (this.m_dialogView);
        }
        protected function onPlaceNowClose(_arg1:GenericPopupEvent):void{
            var _local2:MarketEvent;
            if (_arg1.button == GenericDialogView.YES){
                _local2 = new MarketEvent(MarketEvent.MARKET_BUY, MarketEvent.GENERIC, this.m_itemNameToPlace);
                _local2.eventSource = MarketEvent.SOURCE_INVENTORY;
                dispatchEvent(_local2);
            };
        }
        public function showWinnings(_arg1:Item):void{
            var _local3:int;
            var _local4:int;
            var _local2:Boolean;
            switch (_arg1.type){
                case "residence":
                    _local3 = _arg1.populationBase;
                    _local2 = (((Global.world.citySim.getTotalPopulation() + _local3))>Global.world.citySim.getPopulationCap()) ? false : true;
                    break;
                case "business":
                    _local4 = Math.floor((Global.world.citySim.getPopulationCap() * Global.gameSettings.getNumber("businessLimitByPopulationMax")));
                    _local2 = (((Global.world.citySim.getTotalBusinesses() + 1))>_local4) ? false : true;
                    break;
                case "decoration":
                    _local2 = true;
            };
            this.m_itemNameToPlace = _arg1.name;
            this.m_winnigItem = _arg1;
            this.m_dialogView.showWinnings(_arg1, _local2);
        }

    }
}//package Display.DialogUI 
